var {App} = require ('../../base/index');
var {
  clickUtils,
  randomUtils,
  logUtils,
  configUtils,
} = require ('../../utils/index');
var pointMap = require ('./pointMap');
var inTask = require ('./inTask');
var aRead = require ('./aRead');
var aTreasure = require ('./aTreasure');
var aPaiShe = require ('./aPaiShe');
var http$ = configUtils.getConfig ('log', 'http', false);

var douYin = new App ('抖音', {
  interval: 10 * 60,
  maxRunTCount: 3,
});
aPaiShe.setStorage (douYin.storage);
douYin.run = function () {
  aRead.flow ();
  sleep (randomUtils.getRandom (2, 3, 100));
  clickUtils.clickPointMap (pointMap.首页.点击赚钱);
  sleep (randomUtils.getRandom (8, 10, 1000));
  inTask.init ();
  sleep (randomUtils.getRandom (2, 3, 1000));
  aTreasure.flow ();
  sleep (randomUtils.getRandom (2, 3, 1000));
  inTask.init ();
  sleep (randomUtils.getRandom (2, 3, 1000));
  aPaiShe.flow ();
  sleep (randomUtils.getRandom (3, 12, 1000));
};
douYin.runTest = function (count) {
  logUtils.info (this.name, 'runTest', count, '/', this.maxRunTCount);
  if (count == 0) {
    sleep (randomUtils.getRandom (2.5, 10, 1000));
    return;
  }
  if (count == 1) {
    aRead.flow ();
    sleep (randomUtils.getRandom (2, 3, 100));
    clickUtils.clickPointMap (pointMap.首页.点击赚钱);
    sleep (randomUtils.getRandom (8, 10, 1000));
    inTask.init ();
    sleep (randomUtils.getRandom (2, 3, 1000));
    return;
  }
  if (count == 2) {
    aRead.flow ();
    var showing = console.showing;
    if (http$) {
      if (showing) {
        console.hide ();
      }
    }
    sleep (randomUtils.getRandom (2, 3, 100));
    clickUtils.clickPointMap (pointMap.首页.点击赚钱);
    sleep (randomUtils.getRandom (8, 10, 1000));
    inTask.init ();
    sleep (randomUtils.getRandom (2, 3, 1000));
    return;
  }
};

module.exports = douYin;
